/**
 * 记录页面的行动路线
 */
const creatRecorder=() => {
  return {
    startTime: undefined,
    endTime: undefined,
    timeLong: 0,
    fromURL: undefined,
    toURL: undefined,
    url: undefined,
    toRouter: undefined,
    fromRouter: undefined,
    fullPath: undefined,
    actions:[]
  }
};
var sid = undefined;
var recorder={};

export function startRecord(router, fr) {
  if (sid) clearInterval(sid);
  recorder=creatRecorder();
  recorder.startTime = new Date().format('yyyy-MM-dd hh:mm:ss');
  recorder.fromURL = document.referrer;
  recorder.url = location.href;
  recorder.fromRouter = fr.fullPath;
  recorder.fullPath = router.fullPath;
  sid = setInterval(() => {
    recorder.timeLong++
  }, 1000);
}

export function saveRecord(to) {
  recorder.endTime = new Date().format('yyyy-MM-dd hh:mm:ss');
  recorder.toRouter = to.fullPath;
  if (sid) clearInterval(sid);
  console.log("页面记录 >>>", JSON.parse(JSON.stringify(recorder)));
}

// action={name:'',btn:'',url:''}
export function addAction(action) {
  recorder.actions.push(action);
}
